package org.edu.modules.center.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.common.system.vo.LoginUser;
import org.edu.modules.center.entity.VeTeachStudentScore;
import org.edu.modules.center.service.ITeachStudentScoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags={"课程分班教学学员成绩"})
@RestController
@RequestMapping({"/center/veTeachStudentScore"})
public class TeachStudentScoreController
        extends BaseController<VeTeachStudentScore, ITeachStudentScoreService>
{
    private static final Logger log = LoggerFactory.getLogger(TeachStudentScoreController.class);
    @Autowired
    private ITeachStudentScoreService veTeachStudentScoreService;

    @AutoLog("课程分班教学学员成绩-查询考核项得分")
    @ApiOperation(value="查询考核项得分", notes="查询考核项得分")
    @PostMapping({"/queryList"})
    public Result<?> queryPageList(VeTeachStudentScore veTeachStudentScore, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req)
    {
        if (veTeachStudentScore.getStudentid().equals(Integer.valueOf(0)))
        {
            LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
            veTeachStudentScore.setStudentid(Integer.valueOf(sysUser.getUserId()));
        }
        QueryWrapper<VeTeachStudentScore> queryWrapper = QueryGenerator.initQueryWrapper(veTeachStudentScore, req.getParameterMap());

        Page<Map<String, Object>> page = new Page(pageNo.intValue(), pageSize.intValue());
        queryWrapper.setEntity(veTeachStudentScore);
        IPage<Map<String, Object>> pageList = this.veTeachStudentScoreService.pageMaps(page, queryWrapper);
        return Result.OK(pageList);
    }

    @AutoLog("课程分班教学学员成绩-查询学员综合成绩")
    @ApiOperation(value="查询学员综合成绩", notes="查询学员综合成绩")
    @PostMapping({"/querySourceList"})
    public Result<?> queryScorePageList(VeTeachStudentScore veTeachStudentScore, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req)
    {
        if (veTeachStudentScore.getStudentid().equals(Integer.valueOf(0)))
        {
            LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
            veTeachStudentScore.setStudentid(Integer.valueOf(sysUser.getUserId()));
        }
        QueryWrapper<VeTeachStudentScore> queryWrapper = QueryGenerator.initQueryWrapper(veTeachStudentScore, req.getParameterMap());

        Page<Map<String, Object>> page = new Page(pageNo.intValue(), pageSize.intValue());
        queryWrapper.setEntity(veTeachStudentScore);
        IPage<Map<String, Object>> pageList = this.veTeachStudentScoreService.scorePageMaps(page, queryWrapper);
        return Result.OK(pageList);
    }

    @AutoLog("课程分班教学学员成绩-查询考核项得分")
    @ApiOperation(value="查询考核项得分", notes="ve_exam_question-查询考核项得分")
    @GetMapping({"/queryScore"})
    public Result<?> queryQuestionList(@RequestParam(name="tcid") String tcid, @RequestParam(name="studentid") String studentid)
    {
        return Result.OK(this.veTeachStudentScoreService.queryScore(tcid, studentid));
    }
}
